export function setJumpNumber(startNum, targetNum, callback) {
    let originNum = startNum;
    let stepNum = 0;
    let timeNum = 50;
    callback(startNum);
    let timeId = setInterval(() => {
        if (originNum < targetNum) {
            timeNum -= 1;
            let strNum = originNum.toString();
            if (targetNum.toString().length < 6) {
                stepNum += 1;
                originNum = originNum + stepNum;
                callback(originNum);
            } else {
                stepNum += 500;
                originNum = originNum + stepNum;
                const num = strNum.substr(0, strNum.length - 3) + Math.floor(Math.random() * 10) + Math.floor(Math.random() * 10) + Math.floor(Math.random() * 10);
                callback(num);
            }
        } else {
            callback(targetNum);
            clearInterval(timeId);
        }
    }, timeNum);
}

export function scrollLeft(itemCount, callback) {
    let change = false
    let start = 0
    callback(0)
    const min = window.innerWidth * 0.3 * itemCount - window.innerWidth
    return setInterval(() => {
        if (change) {
            if (start >= 0) change = false
            start += 3
        } else {
            if (start <= -min) change = true
            start -= 3
        }
        callback(start)
    }, 20)
}

export function scrollRight(itemCount, callback) {
    let change = false
    const max = window.innerWidth * 0.3 * itemCount - window.innerWidth
    let start = -max;
    return setInterval(() => {
        if (change) {
            if (start <= -max) change = false
            start -= 3
        } else {
            if (start >= 0) change = true
            start += 3
        }
        callback(start)
    }, 20)
}